package com.thero.core.chess;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wusk on 2017/11/27.
 * 玩家类
 */
public class Player {
    public static final int PIECE_COUNT = 9;
    private short home;
    private int id;
    private int count;
    private int rival;
    private Color color;
    private List<Piece> pieces;

    public Player(short home, int id, int rival, Color color){
        this.id = id;
        this.home = home;
        this.rival = rival;
        this.count = PIECE_COUNT;
        this.color = color;
        pieces = new ArrayList<>(PIECE_COUNT);
        for(int i = 0; i < PIECE_COUNT; i++){
            Piece piece = new Piece(color);
            pieces.add(piece);
        }
    }

    public int getId(){
        return this.id;
    }

    public short getHome(){
        return this.home;
    }

    public boolean havePieces(){
        return this.count > 0;
    }

    public Piece takePiece(){
        if(this.count == 0){
            return null;
        }
        Piece piece = this.pieces.get(count - 1);
        this.count = this.count - 1;
        return piece;
    }

    public Color selfColor(){
        return this.color;
    }

    public Color rivalColor(){
        if(color.equals(Color.black)){
            return Color.white;
        }
        return Color.black;
    }

    public int getRival(){
        return this.rival;
    }

    public void setRival(int rival){
        this.rival = rival;
    }
}
